var UserWithDrawals = app.controller('UserWithDrawals', function($rootScope,$stateParams, $scope, $http,$state,$timeout,$cordovaDevice,$cordovaChat,UserWithDrawalsData) {
	try{
		$rootScope.showf=false;
		$scope.busy = false;
		$scope.p=100;
		$scope.bank='';
		$scope.depositbank='';
		$scope.bankcode='';
		$scope.holder='';
		$scope.alipaycode='';

		$scope.pay='bank';


		$scope.info={};
		var url=SITE_URL+"index.php?app=baseloginapp&act=cathinfo&callback=JSON_CALLBACK";
		$http.jsonp(url).success( function(data) {
			if(data.done){
				$scope.info=data.retval;
				if($scope.info!=null){
					
					if($scope.info.cash_type=='银行'){
						$scope.pay='bank';
						$scope.bank=$scope.info.bank;
						$scope.depositbank=$scope.info.deposit_bank;
						$scope.bankcode=$scope.info.bank_code;
						$scope.holder=$scope.info.holder;
					}
					
					if($scope.info.cash_type=='淘宝'){
						$scope.pay='alipay';
						$scope.alipaycode=$scope.info.bank_code;
					}
					
					
				}
			}
		});	

		$scope.keyPress=function(e){
			if(e.which==13){
				$scope.cash();
			}
		}
		$scope.keyPressNext=function(e){
			if(e.which==13||e.which==9){
				$scope.cash();
			}
		}
		//提现
		$scope.cash=function(){
			if($scope.busy){
				return false;
			}


			if($scope.pay=='bank'){
				if($scope.bank==undefined||$scope.bank==''){
					showtoast('请填写开户银行');
					return;
				}
				if($scope.bankcode==undefined||$scope.bankcode==''){
					showtoast('请填写银行卡号');
					return;
				}
				if($scope.holder==undefined||$scope.holder==''){
					showtoast('请填写银行开户人');
					return;
				}
			}
			
			if($scope.pay=='alipay'){
				if($scope.alipaycode==undefined||$scope.alipaycode==''){
					showtoast('请填写支付宝账号');
					return;
				}
			}

			if($scope.p==0){
				showtoast('请填写提现金额');
				return;
			}

			if($scope.p<100){
				showtoast('单次提现金额必须大于100');
				return;
			}

			$scope.busy=true;
			var url=SITE_URL+"index.php?app=baseloginapp&act=withdrawals&callback=JSON_CALLBACK&p="
			+$scope.p+"&bank="+$scope.bank+"&bankcode="+$scope.bankcode
			+"&alipaycode="+$scope.alipaycode
			+"&holder="+$scope.holder+"&type="+$scope.pay;
			$http.jsonp(url).success( function(data) {
				if(data.done){
					showtoast(data.msg);
					$rootScope.go("withdrawalslist");
				}else{
					$scope.busy=false;
				}
			}).error(function(){$scope.busy=false;});	
		}

	}
	catch (e) {
		showcatch(e);
	}
});
UserWithDrawals.UserWithDrawalsData=function($q, $http,$stateParams,$rootScope){
	try {
		var data = [];
		var def = $q.defer();
		if(window.localStorage.u==undefined||window.localStorage.u==null||window.localStorage.u==""){			
			$rootScope.go("loginmain");
		}else{
			def.resolve(data);
		}

		return def.promise;
	} catch (e) {
		showcatch(e);
	}
}